package tjs.study.notes.eureka.clienta.user.service.feign;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import tjs.study.notes.eureka.clienta.user.service.feign.exception.FeignConfigFallbackFactory;
import tjs.study.notes.eureka.clienta.user.service.feign.exception.ThrowErrException;

/**
 * factoryBean: {@link org.springframework.cloud.openfeign.FeignClientFactoryBean#getObject()}
 * <p>
 * jdk代理切面 {@link feign.hystrix.HystrixInvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])}
 * (HystrixInvocationHandler.this.dispatch.get(method)).invoke(args);//key-method)
 *
 * @program: tjs-study-notes
 * @desc:
 * @author: tjs
 * @create: 2021-11-01 13:36
 */
@FeignClient(value = "ms-consumer-order", path = "/order"
        //因为如果FeignClient同时定义fallback/fallbackFactory与configuration时，两个方法都会进入，所以要根据实际情况使用具体的config
        //, fallback = FeignConfigFallbackFactory.class                 //不能获取错误信息
        , fallbackFactory = FeignConfigFallbackFactory.class             //可以获取错误信息
        , configuration = {FeignConfig.class, ThrowErrException.class}  //捕获自定义异常
)
public interface OrederFeignApi {
    @RequestMapping(path = "/newOrder/{userId}/{sleepTime}")
    String newOrder(@PathVariable("userId") String userId, @PathVariable("sleepTime") Integer sleepTime);
}
